package com.lecyon.farm.base;

import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * @param <T>
 * @author YaoZheng
 */
public class BaseRequestVo<T> extends BaseRestRequest {

    T entity;

    public T getEntity(Class<T> clazz) {
        if (clazz == String.class) {
            return (T) entity.toString();
        }
        if (clazz.isInstance(entity)) {
            return entity;
        }
        return JSONObject.parseObject(entity.toString(), clazz);
    }

    public List<T> getList(Class<T> clazz) {
        return JSONObject.parseArray(entity.toString(), clazz);
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }
}
